home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / decprom / RCS / fileLoad.c,v < prev    next >
Encoding:
Text File  |  1990-02-17  |  2.7 KB  |  127 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.16.16.14.08;  author shirriff;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * fileLoad.c --
  27.  *
  28.  *    The routine to load a program into main memory.
  29.  *
  30.  * Copyright 1986 Regents of the University of California
  31.  * All rights reserved.
  32.  */
  33.  
  34. #ifdef notdef
  35. static char rcsid[] = "$Header: /sprite/src/boot/dsprom/RCS/fileLoad.c,v 1.1 90/02/13 23:40:31 shirriff Exp $ SPRITE (Berkeley)";
  36. #endif not lint
  37.  
  38. #include "sprite.h"
  39. #include "fsBoot.h"
  40. #include "kernel/procMach.h"
  41. #include "kernel/machMon.h"
  42. #include "boot.h"
  43.  
  44. #define KERNEL_ENTRY KERNEL_START
  45.  
  46.  
  47. /*
  48.  *----------------------------------------------------------------------
  49.  *
  50.  * FileLoad --
  51.  *
  52.  *    Read in the kernel object file.  This is loaded into memory at
  53.  *    a pre-defined location (in spite of what is in the a.out header)
  54.  *    for compatibility with Sun/UNIX boot programs.  The Sprite kernel
  55.  *    expects to be loaded into the wrong place and does some re-mapping
  56.  *    to relocate the kernel into high virtual memory.
  57.  *
  58.  * Results:
  59.  *    The entry point.
  60.  *
  61.  * Side effects:
  62.  *    None.
  63.  *
  64.  *----------------------------------------------------------------------
  65.  */
  66.  
  67.  
  68. int
  69. FileLoad(handlePtr)
  70.     register Fsio_FileIOHandle    *handlePtr;
  71. {
  72.     ProcExecHeader    aout;
  73.     int            bytesRead;
  74.     register int    *addr;
  75.     register ReturnStatus status;
  76.     register int    i;
  77.     register int    numBytes;
  78.  
  79.     /*
  80.      * Read a.out header.
  81.      */
  82.  
  83.     status = Fs_Read(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  84.     if (status != SUCCESS || bytesRead != sizeof(aout)) {
  85.     Mach_MonPrintf("No a.out header");
  86.     goto readError;
  87.     } else if (aout.aoutHeader.magic != PROC_OMAGIC) {
  88.     Mach_MonPrintf("A.out? mag %x size %d+%d+%d\n",
  89.         aout.aoutHeader.magic, aout.aoutHeader.codeSize,
  90.         aout.aoutHeader.heapSize, aout.aoutHeader.bssSize);
  91.     return(-1);
  92.     }
  93.  
  94.     /*
  95.      * Read the code and initialized data.
  96.      */
  97.  
  98.     numBytes = aout.aoutHeader.codeSize + aout.aoutHeader.heapSize;
  99.     Mach_MonPrintf("Size: %d+%d", aout.aoutHeader.codeSize,
  100.         aout.aoutHeader.heapSize);
  101.     status = Fs_Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  102.               aout.aoutHeader.codeStart, &bytesRead);
  103.  
  104.     if (status != SUCCESS) {
  105. readError:
  106.     Mach_MonPrintf("\nRead error <%x>\n", status);
  107.     return(-1);
  108.     } else if (bytesRead != numBytes) {
  109. shortRead:
  110.     Mach_MonPrintf("\nShort read (%d)\n", bytesRead);
  111.     return(-1);
  112.     }
  113.  
  114.     /*
  115.      * Zero out the bss.
  116.      */
  117.  
  118.     numBytes = aout.aoutHeader.bssSize;
  119.     Mach_MonPrintf("+%d\n", numBytes);
  120.     addr = (int *) (KERNEL_ENTRY + aout.aoutHeader.codeSize +
  121.         aout.aoutHeader.bssSize);
  122.     bzero(addr, numBytes);
  123.  
  124.     return ((int)aout.aoutHeader.entry);
  125. }
  126. @
  127.